package com.skp.shaphan.menus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

import com.skp.shaphan.ShaphanApp;
import com.skp.shaphan.actions.ExecuteSQLAction;

/**
 * Runs the SQL Statement that is currently active
 * @author Stephen Phillips
 *
 */
public class SQLRunMenuItem extends JMenuItem implements ActionListener {
	ExecuteSQLAction action;
	
	/**
	 * Create the new menu item
	 */
	public SQLRunMenuItem() {
		super("Run");
		this.setMnemonic('R');
		this.addActionListener(this);
		action = null;
	}

	/**
	 * Execute when the menu is clicked
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		if(action != null) {
			System.out.println("Thread state = " + action.getState().ordinal() + " -- " + action.getState().name());
		}
		action = new ExecuteSQLAction();
		action.setEditor(ShaphanApp.getMainWindow().getSqlEditor());
		action.setResultPane(ShaphanApp.getMainWindow().getResultPane());
		action.start();
	}
}
